<template>
  <el-menu
    class="menu full-height"
    unique-opened
    router
    style="margin: 0"
    :default-active="menuIndex"
    :collapse="collapsed && !isDrawer"
    :background-color="backgroundColor"
    :text-color="textColor"
    :active-text-color="activeTextColor"
    @select="selectMenu"
  >
    <template v-if="isDrawer">
      <div
          class="el-menu-item title is-disabled"
          :style="{opacity:1, textAlign: 'center'}"
      >
        <span>Cloud Storage</span>
      </div>
      <el-menu-item-group>
        <template #title>
          <span style="white-space: nowrap">控制台</span>
        </template>
      </el-menu-item-group>
    </template>
    <template v-else>
      <div
          class="el-menu-item title"
          @click="$emit('update:collapsed', !collapsed)"
      >
        <i class="el-icon-cloudy"/>
        <span v-if="!collapsed" style="{color: #fff}">Cloud-Storage</span>
      </div>
    </template>
    <el-menu-item index="/files">
      <i class="el-icon-files"></i>
      <template #title>
        <span>我的资源</span>
      </template>
    </el-menu-item>
    <el-menu-item index="/tasks">
      <i class="el-icon-box"></i>
      <template #title>
        <span>管理任务</span>
      </template>
    </el-menu-item>
  </el-menu>
</template>

<script>
export default {
    name: 'Navigator',
    props: {
        isDrawer: {
            type: Boolean,
            default: false
        },
        collapsed: {
            type: Boolean,
            default: false
        }
    },
    emits: ['select'],
    data() {
        return {
            backgroundColor: '00000000',
            textColor: '#fff',
            activeTextColor: '#ffd04b'
        }
    },
    computed: {
        menuIndex() {
            const {menuIndex} = this.$route.meta
            if(typeof menuIndex === 'function') {
                return menuIndex(this.$route)
            }
            return menuIndex
        }
    },
    methods: {
        selectMenu(e) {
            if(this.isDrawer) {
                this.$emit('select', e)
            }
        }
    }
}
</script>

<style lang="less">
.menu {
  background-color: #1fc8db;
  background-image: linear-gradient(141deg,#9fb8ad 0%,#1fc8db 51%,#2cb5e8 75%);
  background-size: cover;

  &:not(.el-menu--collapse) {
    width: 250px;
    min-height: 400px;
  }


  .el-menu, .el-menu-item {
    background-color: rgba(0, 0, 0, 0) !important;
  }
  .el-menu-item:hover {
    background-color: #1fc8db !important;
  }

  .el-menu-item:focus {
    background-color: #1fc8db !important;
  }
}

</style>

<style scoped>
.title {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0 10px;
}
.title span {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffffff;
}

.title i {
    font-size: 2em;
    margin-right: 10px;
    margin-left: 8px;
}
</style>